package com.umeox.moto.watch.fitness.db

import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.umeox.moto.watch.fitness.base.BaseApp
import com.umeox.moto.watch.fitness.db.dao.ChallengeRecordDao
import com.umeox.moto.watch.fitness.db.dao.TodayChallengeDao
import com.umeox.moto.watch.fitness.db.model.ChallengeRecord
import com.umeox.moto.watch.fitness.db.model.TodayChallenge

/**
 * Created by Rambo 2021/8/18
 * Describe:
 */
@Database(entities = [ChallengeRecord::class,TodayChallenge::class], version = 1, exportSchema = false)
abstract class AppDatabase : RoomDatabase() {

    abstract fun challengeRecordDao(): ChallengeRecordDao

    abstract fun todayChallengeDao() : TodayChallengeDao


    companion object {
        private var instance: AppDatabase? = null

        @Synchronized
        fun get(): AppDatabase {
            if (null == instance) instance = Room.databaseBuilder(
                BaseApp.getAppContext().applicationContext,
                AppDatabase::class.java,
                "umeox_fitness.db"
            )
                .allowMainThreadQueries().build()
            return instance as AppDatabase
        }
    }
}